import { getCompanyInfoTree } from '@/api/company'
import { getSysCompanyBases } from '@/api/system'
import { getNewAlarmInfo } from '@/api/home'
let mixin = {
  created() {
    this.getCompanyInfoTree()
  },
  data() {
    return {
      companyArray: [],
      baseArray: [],
      AllalarmList: [],
      typeif: 1,
      timerAll: '',
      baseID: ''
    }
  },

  methods: {
    // 获取公司列表
    getCompanyInfoTree() {
      if (Number(window.localStorage.getItem('userType')) == 0) {
        // 超级管理员，公司只有一个总公司
        getCompanyInfoTree().then(res => {
          if (res.code == 200) {
            this.companyArray = res.data
            this.searchForm.companyId = this.companyArray[0].childList[0].id
            this.getSysCompanyBases()
          }
        })
      } else {
        getCompanyInfoTree({ id: 0 }).then(res => {
          if (res.code == 200) {
            this.companyArray = res.data
            this.searchForm.companyId = this.companyArray[0].id
            this.getSysCompanyBases()
          }
        })
      }
    },
    // 获取基地列表
    getSysCompanyBases() {
      if (this.searchForm.companyId === '' || this.searchForm.companyId == null) {
        return
      }
      getSysCompanyBases({ id: this.searchForm.companyId }).then(res => {
        if (res.code == 200) {
          this.baseArray = res.data
          if (res.data.length != 0) {
            this.searchForm.baseId = this.baseArray[0].id
          }
        }
      })
    }
  }
}
export default mixin
